package com.ketai.dao.impl;

import com.ketai.dao.BaseDao;
import com.ketai.dao.CUserDao;
import com.ketai.pojo.CUser;
import com.ketai.vo.CUserVo;

import javax.naming.NamingException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author:胡远博
 * @Description:
 * @Date:Create In 2022-08-08 9:22
 **/
public class CUserDaoImpl extends BaseDao implements CUserDao {
    @Override
    public List<CUser> findAll(String sql, Object[] params) throws SQLException, NamingException {
        List<CUser> list = new ArrayList<CUser>();
        ResultSet rs = query(sql, params);
        while (rs.next()) {
            CUser user = new CUser();
            user.setId(rs.getString("id"));
            user.setNickname(rs.getString("nickname"));
            String sex = rs.getInt("sex") == 0 ? "女" : "男";
            user.setSex(sex);
            user.setCity(rs.getString("city"));
            user.setCreate_time(rs.getString("create_time"));
            list.add(user);
        }
        return list;
    }

    @Override
    public long getTotalCUserCount(String sql, Object[] params) throws SQLException, NamingException {
        ResultSet rs = query(sql, params);
        while (rs.next()) {
            return rs.getLong("total");
        }

        return 0;
    }


}
